﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GbmpModel.h"
#include "IElevationViewSymbolNew.h"
#include "DbDataSchema.h"
#include "RegenDataSchema.h"
#include "ElementId.h"
#include "IModelViewEventHandler.h"
#include "IElementDeletionComponent.h"

namespace gcmp
{
    class IElement;
    class IDocument;
    class IGraphicsElementShape;
    class IModelView;

    class GBMP_MODEL_EXPORT ElevationViewSymbolNew : public NdbObjectSchematic, public IElevationViewSymbolNew
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ElevationViewSymbolNew, gcmp::NdbObjectSchematic, EF260617 - 80B7 - 4422 - BEFF - 06DD4B9695C4, gbmpmodel, IElevationViewSymbolNew)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(ElementId,ElevationModelViewId) //立面视图Id
            DATA_CUSTOM(Bool, MarkChanged,gcmp::PBT_Transient|gcmp::PBT_SupportCopy|gcmp::PBT_SupportTransaction) //为刷新视图设置的标记位
            DATA_WITHOUT_CHECK_AND_SUPPORT(OwnerPtr<IModelViewEventHandler>, ModelViewEventHandler)
            DATA_REGEN(Bool,ModelViewRangeUpdated)
        DBOBJECT_DATA_END

    public:
        virtual ~ElevationViewSymbolNew() {}

#pragma region static methods
    public:
        static IElevationViewSymbolNew* Create(IDocument *pDoc, ElementId elevationModelViewId);

        static gcmp::UniIdentity GetImplementationUid();
#pragma endregion static methods

#pragma region IExternalObject 接口
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override;
        virtual const IElement* GetOwnerElement() const override;
        virtual IElement* GetOwnerElement() override;

        virtual NdbObject* GetTopOwnerObject() const override;

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;

        virtual void ReportParents(IElementParentReporter& reporter) const override;

        virtual bool FinishEditing() override;

#pragma endregion IExternalObject 接口

#pragma region IElevationViewSymbolNew 接口
    public:
        virtual ElementId GetModelViewId() const override;

        virtual ElementId GetOwnerElementId() const override;

#pragma endregion IElevationViewSymbolNew 接口

#pragma region 其他
    public:
        OwnerPtr<IGraphicsElementShape> CreateModelViewElementShape(const IModelView* pModelView) const;

        bool MakeTransform(const Matrix4d& matrix);

        void MarkChanged();

        IDocument* GetDocument() const;

        IModelView* GetElevationModelView() const;

#pragma endregion 其他

    private:
        bool GetElevationModelViewViewPointAndViewDirectionProjectedOnLevelModelView(const IModelView *pElevationModelView,const IModelView* pLevelModelView, Vector3d &viewPoint, Vector3d &viewDir) const;
        bool GetModelViewViewScaleAndNormalizedUVWDirection(const IModelView *pModelView, double &viewScale, Vector3d &uDir, Vector3d &vDir, Vector3d &wDir) const ;
        void SetElevationModelViewId(const ElementId& viewId);
        bool SubscribeModelViewEvent();
        bool UnsubscribeModelViewEvent();
    };
}
